package com.fsnbigdata.repository;

import com.fsnbigdata.domain.*;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;

/**
 * Created by zq on 2019/4/20.
 */
@RooJpaRepositoryCustomImpl(repository = AnimalConservationImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class AnimalConservationImageRepositoryImpl  extends QueryDslRepositorySupportExt<AnimalConservationImage> implements AnimalConservationImageRepositoryCustom{

    /**
     * TODO Auto-generated constructor documentation
     */
    AnimalConservationImageRepositoryImpl() {
        super(AnimalConservationImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ANIMAL_CONSERVATION = "animalConservation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated method documentation
     *
     * @param
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<AnimalConservationImage> findByAnimalConservation(AnimalConservation animalConservation, GlobalSearch globalSearch, Pageable pageable) {
        QAnimalConservationImage aimalConservationImage = QAnimalConservationImage.animalConservationImage;
        JPQLQuery<AnimalConservationImage> query = from(aimalConservationImage);
        Assert.notNull(animalConservation, "animalConservation is required");
        query.where(aimalConservationImage.animalConservation.eq(animalConservation));
        Path<?>[] paths = new Path<?>[] { aimalConservationImage.animalConservation, aimalConservationImage.code, aimalConservationImage.description, aimalConservationImage.location, aimalConservationImage.author, aimalConservationImage.url, aimalConservationImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        QueryDslRepositorySupportExt.AttributeMappingBuilder mapping = buildMapper().map(ANIMAL_CONSERVATION, aimalConservationImage.animalConservation).map(CODE, aimalConservationImage.code).map(DESCRIPTION, aimalConservationImage.description).map(LOCATION, aimalConservationImage.location).map(AUTHOR, aimalConservationImage.author).map(URL, aimalConservationImage.url).map(CREATE_DATE, aimalConservationImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, aimalConservationImage);
    }
}
